class Solution
{
public:
    int sumOddLengthSubarrays(vector<int> &arr)
    {
        int sum = 0;
        int n = arr.size();
        for (int i = 0; i < n; ++i)
        {
            int leftLen = i;
            int rightLen = n - i - 1;
            sum += arr[i] * ((leftLen / 2 + 1) * (rightLen / 2 + 1) + (leftLen + 1) / 2 * ((rightLen + 1) / 2));
        }
        return sum;
    }
};